From 72e6566b0d3811b3d711bb6b077b33082f07379b Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Mon, 22 Oct 2001 19:13:28 +0000 Subject: [PATCH] Clarify behavior in docs, #61777 (gtk_text_iter_forward_search) 2001-10-22 Havoc Pennington * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in docs, #61777 (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): change the two boolean args to a flags field, so we can extend to add case insensitive, regexp searches later. #61852 --- ChangeLog | 8 +++++ ChangeLog.pre-2-0 | 8 +++++ ChangeLog.pre-2-10 | 8 +++++ ChangeLog.pre-2-2 | 8 +++++ ChangeLog.pre-2-4 | 8 +++++ ChangeLog.pre-2-6 | 8 +++++ ChangeLog.pre-2-8 | 8 +++++ docs/reference/gtk/tmpl/gtkmenu.sgml | 6 ++-- docs/reference/gtk/tmpl/gtktextiter.sgml | 12 ++++--- gtk/gtktextiter.c | 46 ++++++++++++++++-------- gtk/gtktextiter.h | 12 ++++--- tests/testtext.c | 8 +++-- 12 files changed, 113 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4ad4aaae81..aed7aa0fba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2001-10-22 Havoc Pennington + + * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in + docs, #61777 + (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): + change the two boolean args to a flags field, so we can extend + to add case insensitive, regexp searches later. #61852 + Mon Oct 22 15:07:17 2001 Jonathan Blandford * gtk/gtktreestore.c (gtk_tree_store_iter_depth): update docs to diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 4ad4aaae81..aed7aa0fba 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,11 @@ +2001-10-22 Havoc Pennington + + * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in + docs, #61777 + (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): + change the two boolean args to a flags field, so we can extend + to add case insensitive, regexp searches later. #61852 + Mon Oct 22 15:07:17 2001 Jonathan Blandford * gtk/gtktreestore.c (gtk_tree_store_iter_depth): update docs to diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4ad4aaae81..aed7aa0fba 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2001-10-22 Havoc Pennington + + * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in + docs, #61777 + (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): + change the two boolean args to a flags field, so we can extend + to add case insensitive, regexp searches later. #61852 + Mon Oct 22 15:07:17 2001 Jonathan Blandford * gtk/gtktreestore.c (gtk_tree_store_iter_depth): update docs to diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 4ad4aaae81..aed7aa0fba 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,11 @@ +2001-10-22 Havoc Pennington + + * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in + docs, #61777 + (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): + change the two boolean args to a flags field, so we can extend + to add case insensitive, regexp searches later. #61852 + Mon Oct 22 15:07:17 2001 Jonathan Blandford * gtk/gtktreestore.c (gtk_tree_store_iter_depth): update docs to diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 4ad4aaae81..aed7aa0fba 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,11 @@ +2001-10-22 Havoc Pennington + + * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in + docs, #61777 + (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): + change the two boolean args to a flags field, so we can extend + to add case insensitive, regexp searches later. #61852 + Mon Oct 22 15:07:17 2001 Jonathan Blandford * gtk/gtktreestore.c (gtk_tree_store_iter_depth): update docs to diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 4ad4aaae81..aed7aa0fba 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,11 @@ +2001-10-22 Havoc Pennington + + * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in + docs, #61777 + (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): + change the two boolean args to a flags field, so we can extend + to add case insensitive, regexp searches later. #61852 + Mon Oct 22 15:07:17 2001 Jonathan Blandford * gtk/gtktreestore.c (gtk_tree_store_iter_depth): update docs to diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4ad4aaae81..aed7aa0fba 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2001-10-22 Havoc Pennington + + * gtk/gtktextiter.c (gtk_text_iter_set_line): Clarify behavior in + docs, #61777 + (gtk_text_iter_forward_search) (gtk_text_iter_backward_search): + change the two boolean args to a flags field, so we can extend + to add case insensitive, regexp searches later. #61852 + Mon Oct 22 15:07:17 2001 Jonathan Blandford * gtk/gtktreestore.c (gtk_tree_store_iter_depth): update docs to diff --git a/docs/reference/gtk/tmpl/gtkmenu.sgml b/docs/reference/gtk/tmpl/gtkmenu.sgml index b8f6c87935..b51c366a4b 100644 --- a/docs/reference/gtk/tmpl/gtkmenu.sgml +++ b/docs/reference/gtk/tmpl/gtkmenu.sgml @@ -96,9 +96,9 @@ Creates a new #GtkMenu. Adds a new #GtkMenuItem to the end of the menu's item list. + @menu: a #GtkMenu. @child: The #GtkMenuItem to add. - @m: @c: @@ -108,9 +108,9 @@ Adds a new #GtkMenuItem to the end of the menu's item list. Adds a new #GtkMenuItem to the beginning of the menu's item list. + @menu: a #GtkMenu. @child: The #GtkMenuItem to add. - @menu_child: @m: @c: @@ -122,10 +122,10 @@ Adds a new #GtkMenuItem to the menu's item list at the position indicated by @position. + @menu: a #GtkMenu. @child: The #GtkMenuItem to add. @pos: - @position: The position in the item list where @child is added. Positions are numbered from 0 to n-1. diff --git a/docs/reference/gtk/tmpl/gtktextiter.sgml b/docs/reference/gtk/tmpl/gtktextiter.sgml index aae67a4ddf..1815bd9654 100644 --- a/docs/reference/gtk/tmpl/gtktextiter.sgml +++ b/docs/reference/gtk/tmpl/gtktextiter.sgml @@ -715,12 +715,14 @@ types related to the text widget and how they work together. @iter: @str: -@visible_only: -@slice: +@flags: @match_start: @match_end: @limit: @Returns: + +@visible_only: +@slice: @@ -730,12 +732,14 @@ types related to the text widget and how they work together. @iter: @str: -@visible_only: -@slice: +@flags: @match_start: @match_end: @limit: @Returns: + +@visible_only: +@slice: diff --git a/gtk/gtktextiter.c b/gtk/gtktextiter.c index 1b8fbf9317..ab387f4cd1 100644 --- a/gtk/gtktextiter.c +++ b/gtk/gtktextiter.c @@ -3632,7 +3632,9 @@ gtk_text_iter_set_visible_line_index (GtkTextIter *iter, * @iter: a #GtkTextIter * @line_number: line number (counted from 0) * - * Moves iterator @iter to the start of the line @line_number. + * Moves iterator @iter to the start of the line @line_number. If + * @line_number is negative or larger than the number of lines in the + * buffer, moves @iter to the start of the last line in the buffer. * **/ void @@ -4243,23 +4245,31 @@ strbreakup (const char *string, * gtk_text_iter_forward_search: * @iter: start of search * @str: a search string - * @visible_only: if %TRUE, search only visible text - * @slice: if %TRUE, @str contains 0xFFFC when we want to match widgets, pixbufs + * @flags: flags affecting how the search is done * @match_start: return location for start of match, or %NULL * @match_end: return location for end of match, or %NULL * @limit: bound for the search, or %NULL for the end of the buffer * - * Searches forward for @str. Any match is returned as the range @match_start, - * @match_end. If you specify @visible_only or @slice, the match may have - * invisible text, pixbufs, or child widgets interspersed in @str. + * Searches forward for @str. Any match is returned as the range + * @match_start, @match_end. The search will not continue past + * @limit. Note that a search is a linear or O(n) operation, so you + * may wish to use @limit to avoid locking up your UI on large + * buffers. * + * If the #GTK_TEXT_SEARCH_VISIBLE_ONLY flag is present, the match may + * have invisible text interspersed in @str. i.e. @str will be a + * possibly-noncontiguous subsequence of the matched range. similarly, + * if you specify #GTK_TEXT_SEARCH_TEXT_ONLY, the match may have + * pixbufs or child widgets mixed inside the matched range. If these + * flags are not given, the match must be exact; the special 0xFFFC + * character in @str will match embedded pixbufs or child widgets. + * * Return value: whether a match was found **/ gboolean gtk_text_iter_forward_search (const GtkTextIter *iter, const gchar *str, - gboolean visible_only, - gboolean slice, + GtkTextSearchFlags flags, GtkTextIter *match_start, GtkTextIter *match_end, const GtkTextIter *limit) @@ -4268,7 +4278,9 @@ gtk_text_iter_forward_search (const GtkTextIter *iter, GtkTextIter match; gboolean retval = FALSE; GtkTextIter search; - + gboolean visible_only; + gboolean slice; + g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (str != NULL, FALSE); @@ -4297,6 +4309,9 @@ gtk_text_iter_forward_search (const GtkTextIter *iter, return FALSE; } + visible_only = (flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0; + slice = (flags & GTK_TEXT_SEARCH_TEXT_ONLY) == 0; + /* locate all lines */ lines = strbreakup (str, "\n", -1); @@ -4563,8 +4578,7 @@ my_strrstr (const gchar *haystack, * gtk_text_iter_backward_search: * @iter: a #GtkTextIter where the search begins * @str: search string - * @visible_only: if %TRUE search only visible text - * @slice: if %TRUE the search string contains 0xFFFC to match pixbufs, widgets + * @flags: bitmask of flags affecting the search * @match_start: return location for start of match, or %NULL * @match_end: return location for end of match, or %NULL * @limit: location of last possible @match_start, or %NULL for start of buffer @@ -4576,8 +4590,7 @@ my_strrstr (const gchar *haystack, gboolean gtk_text_iter_backward_search (const GtkTextIter *iter, const gchar *str, - gboolean visible_only, - gboolean slice, + GtkTextSearchFlags flags, GtkTextIter *match_start, GtkTextIter *match_end, const GtkTextIter *limit) @@ -4587,7 +4600,9 @@ gtk_text_iter_backward_search (const GtkTextIter *iter, gint n_lines; LinesWindow win; gboolean retval = FALSE; - + gboolean visible_only; + gboolean slice; + g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (str != NULL, FALSE); @@ -4615,6 +4630,9 @@ gtk_text_iter_backward_search (const GtkTextIter *iter, return FALSE; } + visible_only = (flags & GTK_TEXT_SEARCH_VISIBLE_ONLY) != 0; + slice = (flags & GTK_TEXT_SEARCH_TEXT_ONLY) == 0; + /* locate all lines */ lines = strbreakup (str, "\n", -1); diff --git a/gtk/gtktextiter.h b/gtk/gtktextiter.h index 8d6096ca9c..887593f01f 100644 --- a/gtk/gtktextiter.h +++ b/gtk/gtktextiter.h @@ -34,6 +34,12 @@ extern "C" { #endif /* __cplusplus */ +typedef enum { + GTK_TEXT_SEARCH_VISIBLE_ONLY, + GTK_TEXT_SEARCH_TEXT_ONLY + /* Possible future plans: SEARCH_CASE_INSENSITIVE, SEARCH_REGEXP */ +} GtkTextSearchFlags; + /* * Iter: represents a location in the text. Becomes invalid if the * characters/pixmaps/widgets (indexable objects) in the text buffer @@ -236,16 +242,14 @@ gboolean gtk_text_iter_backward_find_char (GtkTextIter *iter, gboolean gtk_text_iter_forward_search (const GtkTextIter *iter, const gchar *str, - gboolean visible_only, - gboolean slice, + GtkTextSearchFlags flags, GtkTextIter *match_start, GtkTextIter *match_end, const GtkTextIter *limit); gboolean gtk_text_iter_backward_search (const GtkTextIter *iter, const gchar *str, - gboolean visible_only, - gboolean slice, + GtkTextSearchFlags flags, GtkTextIter *match_start, GtkTextIter *match_end, const GtkTextIter *limit); diff --git a/tests/testtext.c b/tests/testtext.c index 09ef2ace26..707c8eb04d 100644 --- a/tests/testtext.c +++ b/tests/testtext.c @@ -1578,7 +1578,9 @@ buffer_search (Buffer *buffer, if (forward) { - while (gtk_text_iter_forward_search (&iter, str, TRUE, FALSE, + while (gtk_text_iter_forward_search (&iter, str, + GTK_TEXT_SEARCH_VISIBLE_ONLY | + GTK_TEXT_SEARCH_TEXT_ONLY, &match_start, &match_end, NULL)) { @@ -1591,7 +1593,9 @@ buffer_search (Buffer *buffer, } else { - while (gtk_text_iter_backward_search (&iter, str, TRUE, FALSE, + while (gtk_text_iter_backward_search (&iter, str, + GTK_TEXT_SEARCH_VISIBLE_ONLY | + GTK_TEXT_SEARCH_TEXT_ONLY, &match_start, &match_end, NULL)) { -- 2.30.2